
<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('Plan/index')}">列表</a></li>
        <li class="active"><a href="{:url('Plan/add')}">添加</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('Plan/addPost')}">
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 计划号:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" readonly type="text" class="form-control" name="name" value="{$name|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 归属类型:</label>
            <div class="col-md-6 col-sm-10">
                <select name="companytype" class=" form-control selectpicker" data-live-search="true">
                    <volist name="companytypea_arr" id="ao">
                        <option
                        <if isset($vo.companytype)&&$vo.companytype==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.name}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 用途类型:</label>
            <div class="col-md-6 col-sm-10">
                <select name="c_type" class=" form-control selectpicker" data-live-search="true">
                    <volist name="c_type_arr" id="ao">
                        <option
                        <if isset($vo.c_type)&&$vo.c_type==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.name}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 计划类型:</label>
            <div class="col-md-6 col-sm-10">
                <select name="type" class="form-control" id="type">
                    <option value="">请选择</option>
                    <option selected value="1">开平</option>

                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 合同编号:</label>
            <div class="col-md-6 col-sm-10">
                <select name="ht_id" class=" form-control selectpicker" data-live-search="true" onchange="htchange()"
                        id="ht_id">
                    <option value="">请选择</option>
                    <volist name="ht_id_arr" id="ao">
                        <option
                        <if isset($vo.ht_id)&&$vo.ht_id==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.ht_number}</option>
                    </volist>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 客户名称:</label>
            <div class="col-md-6 col-sm-10">
                <select name="company_id" class=" form-control selectpicker" data-live-search="true" id="company_id">
                    <option value="">请选择</option>
                    <volist name="company_id_arr" id="ao">
                        <option
                        <if isset($vo.company_id)&&$vo.company_id==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.name}(简称:{$ao.abb_name})</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 牌号:</label>
            <div class="col-md-6 col-sm-10">
                <select name="grade_id" class=" form-control selectpicker" data-live-search="true" id="grade_id"
                        onchange="getsteelgrade()">
                    <option value="">请选择</option>
                    <volist name="grade_id_arr" id="ao">
                        <option
                        <if isset($vo.grade_id)&&$vo.grade_id==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.g_name}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 钢种:</label>
            <div class="col-md-6 col-sm-10">
                <select name="steel_grade_id" class=" form-control selectpicker" data-live-search="true"
                        id="steel_grade_id" onchange="getcoil()">
                    <option value="">请选择</option>
                    <volist name="steel_grade_id_arr" id="ao">
                        <option
                        <if isset($vo.steel_grade_id)&&$vo.steel_grade_id==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.name}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 交付时间:</label>
            <div class="col-md-6 col-sm-10">
                <input autocomplete="off" type="text" class="form-control js-datetime" id="delivery_time"
                       name="delivery_time"
                       value="{$now_time|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 生产日期:</label>
            <div class="col-md-6 col-sm-10">
                <input autocomplete="off" type="text" class="form-control js-datetime" name="pd"
                       value="{$now_time|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 钢卷信息:</label>
            <div class="col-md-6 col-sm-10">
                <select name="coil_id[]" id="coil_id" class="multiselect form-control selectpicker " multiple="multiple"
                        data-live-search="true" onchange="getcoil()">
                    <volist name="coil_id_arr" id="ao">
                        <option
                        <if isset($vo.coil_id)&&$vo.companytype==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.name}-{$ao.coilno}-{$ao.product}-{$steel_grade_arr_da[$ao.steel_grade_id]}-{$ao.d}*{$ao.w}*{$ao.h}-{$ao.weight-$ao.occupied_we}吨</option>
                    </volist>
                </select>
            </div>

        </div>
        <div class="form-group">


            <label class="col-sm-2 control-label"><span class="form-required"></span> 厚:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="d" name="d" value="{$vo.d|default=''}">
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 宽:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="w" name="w" value="{$vo.w|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 长1:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="h" name="h" value="{$vo.h|default=''}">
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 张数1:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="sheets1" name="sheets"
                       value="{$vo.sheets|default=''}">

            </div>
            <a class="btn btn-primary" onclick="jisuan()">计算</a>
        </div>


        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 长2:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="h2" name="h2" value="{$vo.h2|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 张数2:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="sheets2" name="sheets2"
                       value="{$vo.sheets|default=''}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 长3:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="h3" name="h3" value="{$vo.h3|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 张数3:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="sheets3" name="sheets3"
                       value="{$vo.sheets|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 图片附件:</label>
            <div class="col-md-6 col-sm-10">
                <input readonly style="display: inline-block;width:80%;" class="form-control" name="image_enclosure"
                       id="image_enclosure"
                       type="text"
                       title="图片名称" value="">
                <a class="btn btn-success"
                   href="javascript:uploadMultiFile('图片上传','#image_enclosureCnt','#image_enclosure','image');">上传</a>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span> 预览</label>
            <div id="image_enclosureCnt" class="col-md-6 col-sm-10">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 文件附件:</label>
            <div class="col-md-6 col-sm-10">
                <input readonly style="display: inline-block;width:80%;" class="form-control" name="file_enclosure"
                       id="file_enclosure"
                       type="text"
                       title="图片名称" value="">
                <a class="btn btn-success"
                   href="javascript:uploadMultiFile('文件上传','#file_enclosureCnt','#file_enclosure','file');">上传</a>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span> 预览</label>
            <div id="file_enclosureCnt" class="col-md-6 col-sm-10">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 备注:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" name="remrk" value="{$vo.remrk|default=''}">
            </div>
        </div>
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
            <a class="btn btn-default" href="{:url('Plan/index')}">返回</a>
        </div>


    </form>

</div>
<script src="/static/js/admin.js"></script>
<script src="/static/js/layer/layer.js"></script>
<script type="text/javascript">


    function jisuan() {

        // ($params['d'] * ($params['w'] / 1000) * ($params['h'] / 1000) * 7.85) / 1000)
        d = $('#d').val()
        w = $('#w').val()
        // w=w/1000
        h = $('#h').val()
        coid_id = $('#coil_id').val()
        if (!d) {
            alert('请填写参数')
            return;
        }
        if (!coid_id) {
            alert('请选择钢卷')
            return;
        }
        if (!w) {
            alert('请填写参数')
            return;
        }
        if (!h) {
            alert('请填写参数')
            return;
        }
        console.log(coid_id)
        console.log(d)
        console.log(w)
        console.log(h)
        // h=h/1000、
        //一张的重量
        sheets = d * w * h * 7.85
        //     $.ajax({
        //         url: '{:url("plan/findid")}',
        //         type:'get',
        //         date: {list:111},
        //         contentType: 'application/json',
        //         success(res)
        //     {
        //         console.log(res)
        //     }
        // })
        $.post('{:url("plan/findid")}',
            {
                coil: coid_id,

            },
            function (data, item) {
                console.log(data);
                sheets = (d * (w / 1000) * (h / 1000) * 7.85) / 1000;
                num = data / sheets
                num = num.toFixed(3);
                // console
                $('#sheets1').val(num);
            });

        // console.log(d)
        // console.log(w)
        // console.log(h)
        // console.log(sheets)

    }

    function htchange() {
        var ht_id = $('#ht_id').val()
        $.ajax({
            url: '{:url("Ht/findid")}?id=' + ht_id,
            type: 'get',
            success(res) {
                console.log(res)
                // company_id: 1
                $('select[name=company_id]').find("option[value=" + res.data.company_id + "]").prop("selected", true);
                // delete_time: 0
                // delivery_time: 1657955400
                $('#delivery_time').val(res.data.delivery_time);
                // ht_d: "6.00"
                $('#d').val(res.data.ht_d);
                // ht_grade_id: "5"
                $('select[name=grade_id]').find("option[value=" + res.data.ht_grade_id + "]").prop("selected", true);

                // getsteelgrade(res.data.ht_grade_id);
                // ht_h: "1700.00"
                $('#h').val(res.data.ht_h);
                // ht_name: "测试001"
                // ht_number: "测试001"
                // ht_sheets: 7
                $('#sheets').val(res.data.ht_sheets);
                // ht_tw: "5768.00"
                // ht_w: "1800.00"
                $('#w').val(res.data.ht_w);
                // id: 6
                getsteelgrade()
            }
        })
    }

    function getsteelgrade() {


        var id = $('#grade_id').val()
        $.ajax({
            url: '{:url("Steelgrade/selctid")}?id=' + id,
            type: 'get',
            success(res) {
                jQuery("#steel_grade_id").empty();

                if (res.code == 1 && res.data.length > 0) {
                    jQuery("#steel_grade_id").prepend("<option value='0'>请选择</option>");   //为Select插入一个Option(第一个位置)

                    for (var i = 0; i < res.data.length; i++) {
                        console.log(res.data[i])
                        jQuery("#steel_grade_id").append("<option value='" + res.data[i]['id'] + "'>" + res.data[i]['name'] + "</option>");
                    }

                }

            }
        })
    }

    function getcoil() {


        var id = $('#coil_id').val()
        console.log(id)
        if (id) {
            oneid = id[0];
            // var id = $('#steel_grade_id').val()
            $.ajax({
                url: '{:url("Plan/selctid")}?id=' + oneid,
                type: 'get',
                success(res) {
                    console.log(res)
                    $('#d').val(res.data[0].d);

                    $('#w').val(res.data[0].w);
                }
            })

        }


    }

    //预览图片
    function bigSee(obj) {
        let src = $(obj).data('src');
        layer.open({
            title: '图片预览',
            area: ['50%', '100%'],
            content: `<iframe style="width:100%;height:100%;border:0;outline:0;" src="${src}"></iframe>`,
        });
    }

    /**
     * 删除图片
     * @param obj
     */
    function delImg(obj, idFlag = '#photo') {

        let oldPath = $(idFlag).val().trim();
        if (!oldPath) {
            return '';
        }

        let deleteRes = [$(obj).data('src')];
        oldPath = oldPath.split(',');
        oldPath = oldPath.filter(v => !deleteRes.some((item) => item === v))

        oldPath = oldPath.join(',');

        $(idFlag).val(oldPath);
        //删除原图片
        $(obj).parent().remove();
    }//预览
    function bigSee(obj) {
        let src = $(obj).data('src');
        layer.open({
            title: '文件预览',
            area: ['50%', '100%'],
            content: `<iframe style="width:100%;height:100%;border:0;outline:0;" src="${src}"></iframe>`,
        });
    }

    /**
     * 删除
     * @param obj
     */
    function delImg(obj, idFlag = '#photo') {

        let oldPath = $(idFlag).val().trim();
        if (!oldPath) {
            return '';
        }

        let deleteRes = [$(obj).data('src')];
        oldPath = oldPath.split(',');
        oldPath = oldPath.filter(v => !deleteRes.some((item) => item === v))

        oldPath = oldPath.join(',');

        $(idFlag).val(oldPath);
        //删除原图片
        $(obj).parent().remove();
    }
</script>
</body>
</html>